package com.system.xingzhi.controller;

import com.system.xingzhi.model.Page;
import com.system.xingzhi.model.ReturnData;
import com.system.xingzhi.model.Role;
import com.system.xingzhi.model.User;
import com.system.xingzhi.service.PageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;


@RestController("/page")
@CrossOrigin
@Api(value = "/page",tags = {"页面"},description = "页面管理")
public class  PageController {

    @Autowired
    private PageService pageService;

    @PostMapping(value="/addPage")
    @ApiOperation(notes = "增加页面",value = "增加页面")
    public ReturnData addPage(@ModelAttribute Page page){
        return  pageService.insert(page);
    }

    @PostMapping(value="/deletePage")
    @ApiOperation(notes = "删除页面",value = "删除页面")
    public ReturnData deletePage(@ApiParam(name = "pageId",value = "页面id") @RequestParam("pageId") String pageId){
        return  pageService.deleteByPrimaryKey(pageId);
    }
    @PostMapping(value="/updatePage")
    @ApiOperation(notes = "更新页面",value = "更新页面")
    public ReturnData updatePage(@ModelAttribute Page page){
        return  pageService.updateByPrimaryKey(page);
    }

    @GetMapping(value="/queryPage")
    @ApiOperation(notes = "页面查询",value = "页面查询")
    public ReturnData queryPage(
            @ApiParam(name = "pageName",value = "页面名") @RequestParam(value = "pageName",required = false) String pageName,
            @ApiParam(name = "pageType",value = "页面类型") @RequestParam(value = "pageType",required = false) String pageType,
            @ApiParam(name = "pagePath",value = "页面路径") @RequestParam(value = "pagePath",required = false) String pagePath,
            @ApiParam(name = "parentName",value = "父页面名") @RequestParam(value = "parentName",required = false) String parentName,
            @ApiParam(name = "pageNum",value = "页码") @RequestParam(value="pageNum") Integer pageNum,
            @ApiParam(name = "pageSize",value = "分页条数") @RequestParam(value="pageSize") Integer pageSize

    ) {
        Map<String, String> map = new HashMap<>();
        map.put("pageName", pageName);
        map.put("pageType", pageType);
        map.put("pagePath", pagePath);
        map.put("parentName", parentName);
        return pageService.selectByParameter(map, pageNum, pageSize);
    }
    @GetMapping(value="/getAllPage")
    @ApiOperation(notes = "获取所有页面",value = "获取所有页面")
    public ReturnData getAllPage() {
        return pageService.getAllPage();
    }
}
